﻿using System;

namespace Cubicle.Core.Processors
{

    public static class EventExtensions
    {

        public static EventHandler EventFilter(
            InstructionEventType type,
            EventArgs eventArgs,
            Action<object, InstructionEventArgs> action)
        {
            return (sender, args) =>
            {
                if (!(eventArgs is InstructionEventArgs)) return;
                var e = (InstructionEventArgs)eventArgs;
                if (e.EventType == type) action(sender, e);
            };
        }

    }

    public enum InstructionEventType
    {
        BeforeCreate,
        AfterCreate,
        BeforePresent,
        AfterPresent,
        BeforeInvoke,
        AfterInvoke,
        BeforeAccessor,
        AfterAccessor,
        BeforeExecute,
        AfterExecute,
        ExecuteException
    }
}